gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\linear\fisher\fisherp.m
function [alphas,solution,t]=fisherp(X,J,K,tmax,t,alphas) % FISHERP learns the Fisher classifier using Perceptron rule. % [alphas,solution,t]=fisherk(X,J,K,tmax,t,alphas) % % FISHERP This algorithm finds the Fisher`s classifier % by the use of the modified Perceptron algorithm. % This task is equivalent to finding solution of % the array of linear nonequalities. The goal is to % find such alphas(:,i), i=1,2,...K that hold % alphas(:,i)'*X(:,k) > alphas(:,j)'*X(:,k) for J(k)=i, i ~= j % % This algorithm works iteratively and find solution in finite % number of steps if the solution exists. % % Input: % X [NxM] matrix containing M training points in N-dimensional % feture space. X=[x1,x2,...xM]. % J [1xM] vector containing M integer class labels for % each point from X. Possible are integer values from 1 to K. % K [1x1] is number of classes. % tmax [1x1] is upper limit of number of algorithm steps. % % t [1x1], alphas [NxK] if these arguments enter function then % the algorithm starts up from the state they define. % The argument t is an initial step number and matrix 'alphas' % contains an initial solution. % % Output: % alphas [NxK] contains found solution. Vector alphas(:,i) coresponds % the to i-th class. % solution [1x1] is equal to 1 if solution was found. % is equal to 0 if was not found. % t [1x1] number of iterations. % % See also FISHERK, FISHDEMO, PERCEPTR, KOZINEC. % % Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac % (c) Czech Technical University Prague, http://cmp.felk.cvut.cz % Written Vojtech Franc (diploma thesis) 02.01.2000 % Modifications % 26-June-2001, V.Franc, comments improved. % 24. 6.00 V. Hlavac, comments polished. % get dim. and # of points N=size(X,1); NX=size(X,2); % default setting if nargin < 5, t=0; end if nargin < 4, tmax=inf; end % STEP (1) if t==0, alphas=zeros(N,K); end % iterate until solution is not found solution = 0; while solution == 0 & tmax > 0, tmax = tmax-1; solution=1; for i=1:NX, b=alphas'*X(:,i); [b,k]=max(b); j=J(i); if k ~= j, % adjust alpha alphas(:,j)=alphas(:,j)+X(:,i); alphas(:,k)=alphas(:,k)-X(:,i); t=t+1; solution=0; break; end end end